package com.dminvoicemanager.backup;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.dminvoicemanager.DM_InvoiceNew;
import com.dminvoicemanager.DM_Settings;
import com.dminvoicemanager.R;
import com.dminvoicemanager.R.id;
import com.dminvoicemanager.R.layout;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class DM_Excel_Generator extends Activity {
	String pdfFileName;
	private String DBNAME = "dminvoicemanager.db";
	private SQLiteDatabase mydb;
	// Main Invoice
	private String TEMP_REP_INVOICESUMERY = "frepInvoiceSumery";
	private String INV_DETAILS = "FinvDet";
	private String INV_HEADER = "FinvHed";
	static Cursor selectInvHeadDetails = null;
	static Cursor selectInvDetDetails = null;

	static int invhedrec = 0;
	static int invdetrec = 0;
	TextView txtHeading;
	public void btnBack(View view) {
		Intent myIntent = new Intent(view.getContext(),
				DM_Settings.class);
		myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
				| Intent.FLAG_ACTIVITY_NEW_TASK);
		myIntent.putExtra("TAGID", "SALES");
		startActivityForResult(myIntent, 0);
		finish();
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dm_excel_generator);

		
		txtHeading = (TextView) findViewById(R.id.txtHeading);

		txtHeading.setText("Excel Backup Generate");
		
		Button addNewInvoice = (Button) findViewById(R.id.writeExcel);
		addNewInvoice.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						DM_Secondry_Invoice_Backup.class);
				myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
						| Intent.FLAG_ACTIVITY_NEW_TASK);
				/* myIntent.putExtra("TAGID", "3"); */
				startActivityForResult(myIntent, 0);
				finish();

			}

		});
		Button backupSalesOrder = (Button) findViewById(R.id.writeExcelSalesOrder);
		backupSalesOrder.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						DM_Sales_Order_Backup.class);
				myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
						| Intent.FLAG_ACTIVITY_NEW_TASK);
				/* myIntent.putExtra("TAGID", "3"); */
				startActivityForResult(myIntent, 0);
				finish();

			}

		});
		Button backupStockLoading = (Button) findViewById(R.id.writeExcelStockLoading);
		backupStockLoading.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						DM_Stock_Loading_Backup.class);
				myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
						| Intent.FLAG_ACTIVITY_NEW_TASK);
				/* myIntent.putExtra("TAGID", "3"); */
				startActivityForResult(myIntent, 0);
				finish();

			}

		});
		
		Button backupStockUnLoading = (Button) findViewById(R.id.writeExcelStockUnLoading);
		backupStockUnLoading.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						DM_Stock_UnLoading_Backup.class);
				myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
						| Intent.FLAG_ACTIVITY_NEW_TASK);
				/* myIntent.putExtra("TAGID", "3"); */
				startActivityForResult(myIntent, 0);
				finish();

			}

		});
		
		Button backupStockAdjustment = (Button) findViewById(R.id.writeExcelStockAdjustment);
		backupStockAdjustment.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						DM_Stock_Adjustment_Backup.class);
				myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
						| Intent.FLAG_ACTIVITY_NEW_TASK);
				/* myIntent.putExtra("TAGID", "3"); */
				startActivityForResult(myIntent, 0);
				finish();

			}

		});

	}
	@Override
	public void onBackPressed() {
		// Do Here what ever you want do on back press;
	}
}
